$(function(){
 loading();
 var language_type = localStorage.getItem("language_type")
 var data = {
  uid: localStorage.getItem("u_id"),
  token: localStorage.getItem("token"),
  language_type: language_type
 }
 $.ajax({
  type:'post',
  url: baseURL + '/index.php?m=index&c=index',
  data: data,
  success: function success(data){
   data = JSON.parse(data);
   is_login(data);
   if(data.code == 1){
    layer.closeAll();
    var indexList = '';
    data.cate.forEach((item) => {
     indexList += `<div class="jui_grid_w50 sy_list_bar">
     <div class="sy_list_con jui_bor_rad_15">
      <div class = " jui_bor_rad_50 ${item.c_status == 0 ? 'sy_list_img2' : 'sy_list_img'}" >
       <img src = "${item.c_img}"> 
      </div>
      <div class="sy_list_tit jui_ellipsis_1">${item.c_name}</div>
      <div class="jui_h16"></div>
      <div class="sy_list_text">
       <span class="jui_flex_no col_fff" data-ch="捕猎时间:" data-en="Hunting time:">捕猎时间：</span>
       <span class="min_time" data-time="${item.c_min_at_time}">${item.c_status == 0 ? '' : item.c_min_at_time}-${item.c_status == 0 ? '-' : item.c_max_at_time}</span>
      </div>
      <div class="sy_list_text">
       <span class="jui_flex_no col_fff" data-ch="价值：" data-en="Price:">价值：</span>
       <span>${item.c_status == 0 ? '' : item.c_min_val}-${item.c_status == 0 ? '-' : item.c_max_val}</span>
      </div>
      <div class="sy_list_text">
       <span class="jui_flex_no col_fff" data-ch="捕猎鸡肉：" data-en="Hunting meat:">捕猎鸡肉：</span>
       <span>${item.c_status == 0 ? '--' : item.c_qg_mic_score}</span>
      </div>
      <div class="sy_list_text">
       <span class="jui_flex_no col_fff" data-ch="捕猎收益：" data-en="Hunting income:">捕猎收益：</span>
       <span>${item.c_status == 0 ? '-' : item.c_con_pro}${item.c_status == 0 ? '' : '%/'}${item.c_status == 0 ? '-' : item.c_con_days}</span>
       <span class=" col_fff" data-ch="${item.c_status == 0 ? '' : '天'}" data-en="${item.c_status == 0 ? '' : 'Day'}"></span>
      </div>
      <div class="sy_list_text">
       <span class="jui_flex_no col_fff" data-ch="饲料：" data-en="Feed:">饲料：</span>
       <span>${item.c_status == 0 ? '--' : item.c_feed}</span>
       <span class=" col_fff" data-ch="${item.c_status == 0 ? '' : '鸡肉/天'}" data-en="${item.c_status == 0 ? '' : 'Feed/day'}">鸡肉/天</span>
      </div>
      <div class="sy_list_jg"></div>
      <div class="sy_btn_bar">
       <div class="jui_flex_row_center jui_flex_justify_center jui_relative jui_pad_b5">
        <img class="sy_list_btn_icon" src="${item.c_status == 0 ? '' : item.c_imge}">
         <div class = "sy_list_btn col_fff ${item.c_status == 1 ? '' : (item.c_status == 0 ? 'sy_list_btn2' : 'jui_bg_b1')}"
          data-id = "${item.id}"
          data-click = "${item.bl_status}"
          data-type = "${item.c_status == 0 ? 0 : (item.c_status == 1 ? 1 : 2)}"
          data-ch = "${item.c_status == 0? '育种' : (item.c_status == 1 ? '捕猎' : '捕猎中')}"
          data-en = "${item.c_status == 0? 'Breeding' : (item.c_status == 1 ? 'Hunt' : 'Hunting')}" >
          ${item.c_status == 0 ? '育种' : (item.c_status == 1 ? '捕猎' : '捕猎中')} 
         </div>
        </div>
       </div>
      </div>
     </div>`
     $("#index_list").html(indexList);
     language()
     documentName()
    })

    var isRenzheng;
    // 实时获取实名认证情况
    var data1 = {
     uid: localStorage.getItem("u_id"),
     token: localStorage.getItem("token"),
     language_type: language_type,
    }
    $.ajax({
     type: 'post',
     url: baseURL + '/index.php?m=user&c=config_setup',
     data: data1,
     success: function success(data) {
      data = JSON.parse(data);
      is_login(data);
      if (data.code == 1) {
       isRenzheng = data.is_check // 是否实名认证 0-没有 1-有 2-待审核
      }
     }
    })
   }
   
   var canClick; // 是否可以点击捕猎按钮 // 1-不能 0-能
   var c_id = ''; // 恐龙的id
   var btn_type = '' // 按钮的种类  0-育种 1-捕猎 2-捕猎中
   // 点击"捕猎"按钮, 弹出提示框
   $(".sy_list_btn").click(function () {
     btn_type = $(this).attr('data-type') == 0 ? '0' : ($(this).attr('data-type') == 1 ? '1' : '2')
     c_id = $(this).attr('data-id');
     canClick = $(this).attr("data-click");

     if (btn_type == 1) {  // 只有当btn_type为1, 且按钮可以被点击, 且实名认证已通过时才能捕猎
      if(canClick == 0){
       if (isRenzheng == 0) {
        box_timer(language_type == 1 ? "实名认证之后才能进行捕猎哦" : " Hunting is allowed after KYC verification has been verified");
        setTimeout(function(){
         window.location.href = 'smrz.html'
        }, 1500);
       } else if (isRenzheng == 2) {
        box_timer(language_type == 1 ? "实名认证审核中,请稍后": "KYC verification is under review, please wait")
       } else { // 实名认证通过
        $(".jui_box_bar").removeClass("jui_none");
        // 点击弹出框的取消按钮, 取消捕猎
        $(".index_close").click(function () {
         $(".jui_box_bar").addClass("jui_none")
        })
        // 点击弹出框的确定按钮, 确定捕猎
        $(".jui_bg_zhuse").click(function () {
         $(".jui_box_bar").addClass("jui_none")
         let data = {
          uid: localStorage.getItem("u_id"),
          token: localStorage.getItem("token"),
          language_type: language_type,
          c_id: c_id
         }
         $.ajax({
          type: 'post',
          url: baseURL + '/index.php?m=index&c=appointment',
          data: data,
          success: function success(data) {
           data = JSON.parse(data);
           is_login(data);
           if (data.code == 1) {
            // canClick = 1; // 捕猎成功,将按钮改为可不点击
            setTimeout(function(){
             window.location.href = 'index.html'
            }, 1000);
            box_timer(data.msg);
           } else {
            box_timer(data.msg);
           }
          }
         })
        })
       }
       
      } else {  // 如果点过捕猎按钮且成功, 给出提示
       box_timer(language_type == 1 ? '您今天已经参与过了' : 'You have been involved today')
      }
     }
   })
   
  }
 })


})